package com.wzy.new_energy_car_platform.controller;


import com.wzy.new_energy_car_platform.common.ResultDto;
import com.wzy.new_energy_car_platform.service.CarService;
import com.wzy.new_energy_car_platform.service.UserCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wzy
 * @since 2024-03-28
 */
@RestController
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarService carService;

    @Autowired
    private UserCollectService userCollectService;

    @GetMapping("/getCarList")
    public ResultDto<?> getCarList(String keyword,String brand,String priceRange,String level,String energy,int page,int pageSize){
         return carService.getCarList(keyword,brand,priceRange,level,energy,page,pageSize);

     }

    @GetMapping("/getCarInfo")
    public ResultDto<?> getCarInfo(int id,String token){
         return carService.getCarInfo(id,token);
     }

    @GetMapping("/getCarModel")
    public ResultDto<?> getCarModel(int id){
         return carService.getCarModel(id);
    }

    @GetMapping("getCarType")
    public ResultDto<?> getCarType(){
        return  carService.getCarType();
    }

    @GetMapping("/getSaleRank")
    public  ResultDto<?> getSaleRank(){
         return carService.getSaleRank();
    }

    @GetMapping("/getMyCollect")
    public ResultDto<?> getMyCollect(int userId){
         return userCollectService.getMyCollect(userId);
    }

    @PostMapping("/addCollect")
    public ResultDto<?> addCollect(@RequestBody Map map){
        return  userCollectService.addCollect(map);
    }

    @PostMapping("/cancelCollect")
    public ResultDto<?> cancelCollect(@RequestBody Map map){
        return  userCollectService.cancelCollect(map);
    }
}
